package com.yun.algorithmproblem.leetcode;

public class Leetcode2843 {

	public static void main(String[] args) {
		Leetcode2843 obj=new Leetcode2843();
		System.out.println(obj.countSymmetricIntegers(1, 1000));
	}

	int[] index;

	public Leetcode2843() {
		index = new int[10001];
		for (int i = 1; i < 10001; i++) {
			if(SymmetricInteger(i)){
				index[i]=index[i-1]+1;
			}else {
				index[i]=index[i-1];
			}
		}
	}

	private Boolean SymmetricInteger(Integer num) {
		String s=num.toString();
		int n=s.length();
		if (n % 2 == 1) {
			return false;
		}
		int leftSum = 0, rightSum = 0;
		for (int i = 0; i < n / 2; i++) {
			leftSum += s.charAt(i) - '0';
			rightSum += s.charAt(n - 1 - i) - '0';
		}
		return leftSum == rightSum;
	}

	public int countSymmetricIntegers(int low, int high) {
		return index[high] - index[low-1];
	}

}
